package com.anjbo.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;

import com.anjbo.bean.system.UserDto;
import com.anjbo.common.Constants;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class BaseController {

	/**
	 * 获取当前登录用户信息
	 * @param request
	 * @return
	 */
	public UserDto getUserDto(HttpServletRequest request) {
		HttpSession session = request.getSession(false);
		return (UserDto) session.getAttribute(Constants.LOGIN_USER_KEY);
	}

	public static String getSid(HttpServletRequest request){
		return (String) request.getAttribute("sid");
	}

	public static String  getDeviceId(HttpServletRequest request){
		return (String) request.getAttribute("deviceId");
	}

	public static String  getDevice(HttpServletRequest request){
		return (String) request.getAttribute("device");
	}
	public static String  getVersion(HttpServletRequest request){
		return (String) request.getAttribute("version");
	}
	public static String  getWxCode(HttpServletRequest request){
		return (String) request.getAttribute("code");
	}

	public ModelAndView getModelAndView(HttpServletRequest request){
		ModelAndView view = new ModelAndView();
		view.addObject("sid", getSid(request));
		view.addObject("deviceId", getDeviceId(request));
		return view;
	}
	public ModelAndView getModelAndView(HttpServletRequest request,String viewName){
		ModelAndView view = new ModelAndView(viewName);
		view.addObject("sid", getSid(request));
		view.addObject("deviceId", getDeviceId(request));
		return view;
	}
}
